/************************************************************************
* 版权所有 
* 
* 文件名称： 
* 文件标识：  
* 内容摘要： 
* 其它说明：  
* 当前版本：  
* 完成日期：  
************************************************************************/
#ifndef __JT808_H
#define __JT808_H

#include "type.h"
/**************************************************************************
 *                            常量                                        *
 **************************************************************************/

#define MSG_HEAD_EXIST_ENC_LEN  17
#define MSG_HEAD_INEXIST_ENC_LEN 13
#define MAX_PLATE_NUM_LEN   	12
#define MAX_Akey_LEN   		30
#define MAX_SET_ARGS_ID 	0x0084
#define MAX_SET_ARGS_PKG_NUM 	4

#define SEND_BYTES_LIMIT	500
#define MAX_PKG_BODY_LEN	1023
#define MAX_PKG_LEN             1042
#define MAX_SEND_BYTES_NUM 	612
#define MAX_VERTEX_NUM  	20
#define MAX_ROUTE_POINT_NUM 	50 
#define MAX_ORG_NAME_LEN    	100
#define MAX_TRANS_CONTENT	300
#define MAX_SIZE		1024

/**************************************************************************
 *                            宏                                          *
 **************************************************************************/


/**************************************************************************
 *                          数据类型                                       *
 **************************************************************************/
typedef struct _SUB_PKG
{
    UINT16 len;
    UINT8 arg[MAX_SEND_BYTES_NUM];

}SUB_PKG;

typedef struct _ENC
{
    UINT16 total; //total pkgs
    UINT16 num;  //pkg num begin 1

}ENC;
typedef struct _MSGHEAD
{
    UINT16 id; //msg id
    UINT16 attr; //msg attr
    UINT8   phone[6];//terminal phone num
    UINT16 seqNum; //msg serial num
    ENC     enc; //msg encapsulation

}MSG_HD;

typedef struct _JT808MSGPKG
{
    UINT8  flagst;
    MSG_HD head;
    UINT8  *pbody;
    UINT8  crc; //check bit
    UINT8  flagend;
}JT808_MSG_PKG;

//0x8001 platform common reply
typedef struct _PLAFM_COM_RPY
{
	UINT16 rpySerNum;
	UINT16 rpyId;
	UINT8  result;
}PLAFM_COM_RPY;

/* Terminal args set table 11 */
typedef struct _ACK_TIMEOUT_STR
{
    UINT32 beatInterval;// 心跳间隔
    UINT32 tcpAckTimeout;
    UINT32 tcpRetransTimes;
    UINT32 udpAckTimeout;
    UINT32 udpRetransTimes;	
    UINT32 smsAckTimeout;
    UINT32 smsRetransTimes;

}ACK_TIMEOUT_STR;

typedef struct _CONNECT_SERVER_STR
{
    UINT8  mainApn[30];
    UINT8  mainUsr[40];
    UINT8  mainCode[40];
    UINT8  mainIp[40];
    UINT8  backupApn[30];
    UINT8  backupUsr[40];
    UINT8  backupCode[40];
    UINT8  backupIp[40];
    UINT16 tcpPort;
    UINT16 udpPort;

}CONNECT_SERVER_STR;

typedef struct _REPORT_ARGS_STR
{

    UINT32 rptWay;//0: 定时1:定距  2:定时和定距
    UINT32 rptStatus;//0:根据ACC状态1:根据登录状态和ACC状态，先判断登录在根据ACC状态
    UINT32 NoLogTmRpt;
    UINT32 NoLogDisRpt;
    UINT32 sleepTmRpt;
    UINT32 sleepDisRpt;
    UINT32 alarmTmRpt;
    UINT32 alarmDisRpt;
    UINT32 dftTmRpt;
    UINT32 dftDisRpt;
    UINT32 angleRpt;//拐点角度补传
    UINT32 trackInterval;
    UINT32 trackIndate;
}REPORT_ARGS_STR;

typedef struct _PHONE_ARGS_STR
{
    UINT8   centreTel[20];
    UINT8   resetTel[20];
    UINT8   facSetTel[20];
    UINT8   centreSmsTel[20];
    UINT8   centreSmsAlarmTel[20];
    UINT16  answerWay;//电话接听策略0:自动接听1:ACC on 自动接听，off时手动
    UINT16  MaxcallTmEach;
    UINT16  MaxcallTmMon;//
    UINT8   monitorTel[20];//监听电话
    UINT8   privilegeSmsTel[20];

}PHONE_ARGS_STR;

typedef struct  _ALARM_ARGS_STR
{
    UINT16 alarmMask;
    UINT16 alarmSmsFlag;
    UINT16 alarmCmrFlag;
    UINT16 alarmCmrSaveFlag;
    UINT16 alarmKeyFlag;
    UINT16 maxSpeed;
    UINT16 overSpeedTm;
    UINT16 conDrvTm;
    UINT16 totalDrvTm;
    UINT16 minRestTm;
    UINT16 MaxStopTm;

}ALARM_ARGS_STR;

/*typedef struct _MEDIA_ARGS_STR
{
    UINT16 picQuality;
    UINT16 light;
    UINT16 contrast;
    UINT16 saturation;
    UINT16 chroma;
}MEDIA_ARGS_STR;
*/
typedef struct _MEDIA_ARGS_STR
{
    UINT8 picQuality;
    UINT8 light;
    UINT8 contrast;
    UINT8 saturation;
    UINT8 chroma;
}MEDIA_ARGS_STR;

//0x8801 take picture immed
typedef struct _TAKE_PICTURE_IMMED
{
	UINT8  passwId;
	UINT16 takeCmd;
	UINT16 takeGapVdTm;
	UINT8  keepFlag;
	UINT8  disting;
	MEDIA_ARGS_STR  picture;
}TAKE_PICTURE_IMMED;

typedef struct _VEHICLE_ARGS_STR
{
    UINT16 mileage;
    UINT16  ProvinceId;
    UINT16  CityId;
    UINT8   PlateNum[MAX_PLATE_NUM_LEN+2];
    UINT8    PlateColor;
}VEHICLE_ARGS_STR;
/* End Terminal args table 11*/

//0x8100 term reg rpy
typedef struct _TERM_REG_RPY
{
	UINT16	rpySerNum;
	UINT8	result;
	UINT8  Akey[MAX_Akey_LEN];	
}TERM_REG_RPY;

//0x8103 set terminal
typedef struct _SET_ARGS_STR
{
    ACK_TIMEOUT_STR                ack;
    CONNECT_SERVER_STR         server;
    REPORT_ARGS_STR                  report;
    PHONE_ARGS_STR		phone;
    ALARM_ARGS_STR                   alarm;
    MEDIA_ARGS_STR                    pic;
    VEHICLE_ARGS_STR               vehicle;
}SET_ARGS_STR;

typedef struct _TERM_ARGS //terminal args table 10
{
	UINT32	argId;
	UINT8	argLen;
	SET_ARGS_STR argValue;
}TERM_ARGS;

typedef struct _CIRCLE_AREA
{
    UINT32 id;
    UINT16 attr;
    UINT32  longitude;
    UINT32  latitude;
    UINT32  radius;
    UINT8    start[6];
    UINT8    end[6];
    UINT16  maxSpeed;
    UINT8    overSpdTm;
    struct _CIRCLE_AREA *next;
}CIRCLE_AREA;

//0x8104 search terminal args

//0x8201 posInfo search

//0x8202 temp pos track ctl
typedef struct _TEMP_POS_TRACK
{
	UINT16	interval;
	UINT32	TraIndate;
}TEMP_POS_TRACK;

//0x8300 text info send
typedef struct _TEXT_INFO_SEND
{
	UINT8	flags;
	UINT8	txtInfo[MAX_SIZE];
}TEXT_INFO_SEND;

//0x8301 event set
typedef struct _EVENT_LIST
{
	UINT8	entId;
	UINT8	entLen;
	UINT8	entCnt[MAX_SIZE];
}EVENT_LIST;

typedef struct _EVENT_SET
{
	UINT8	setType;
	UINT8	setTal;
	EVENT_LIST entList;
}EVENT_SET;

//0x8302 question send
typedef struct _CANDATE_ANSWER
{
	UINT8	answId;
	UINT16	answLen;
	UINT8	answCnt[MAX_SIZE];
}CANDATE_ANSWER;

typedef struct _QUES_SEND
{
	UINT8	flags;
	UINT8	quesLen;
	UINT8	quesCnt[MAX_SIZE];
	CANDATE_ANSWER	anwer;	
}QUES_SEND;

//0x8303 info on demand
typedef struct _INFO_LIST
{
	UINT8	type;
	UINT8 	name[128];
}INFO_LIST;

/*typedef struct _IOD_MENU_SET
{
	INT32 setRect_area;
	UINT8	setType;
	UINT8	infoTal;
	INFO_LIST infoList;	
}IOD_MENU_SET;
*/
//0x8304 info service ok!

//0x8400 callback
typedef struct _CALL_BACK
{
	UINT8	flags;
	UINT8	phone[20];
}CALL_BACK;

//0x8401 set contacts
typedef struct _CONTACT
{
	UINT8	flags;
	UINT8	sim[6];
	UINT8	name[20];
}CONTACT;

//0x8500 vehicle ctl
typedef struct _VEHICLE_CTL
{
	UINT8	ctlFlags;
}VEHICLE_CTL;

typedef struct _RECT_AREA
{
   UINT32  id;
   UINT16  attr;
   UINT32  topLLat;
   UINT32  topLLon;
   UINT32  botRLat;
   UINT32  botRLon;
   UINT8    start[6];
   UINT8    end[6];
   UINT16  maxSpeed;
   UINT8    overSpdTm;
   struct _RECT_AREA *next;
}RECT_AREA;

typedef struct _VERTEX_STR
{
    UINT32  longitude;
    UINT32  latitude;
}VERTEX_STR;

//0x8604 set polygon area
typedef struct _POLYGON_AREA
{
    UINT32 id;
    UINT16 attr;
    UINT8    start[6];
    UINT8    end[6];
    UINT16  maxSpeed;
    UINT8    overSpdTm;
    UINT16    verTotal;
    VERTEX_STR  ver[MAX_VERTEX_NUM];
   struct _POLYGON_AREA *next; 
}POLYGON_AREA;

typedef struct _POINT
{
	UINT32 pntId;
	UINT32 roadId;
	UINT32  latitude;
	UINT32  longitude;
	UINT8 width;
	UINT8 attr;
	UINT16 maxDrvTm;
	UINT16 minDrvTm;
	UINT16 maxSpd;
	UINT8 overSpdTm;
}POINT;

//0x8606 set route
typedef struct _ROUTE
{
	UINT32 id;
	UINT16 attr;
	UINT8    start[6];
	UINT8    end[6];
	UINT16  pntTotal;
	POINT   pnt[MAX_ROUTE_POINT_NUM];
	struct _ROUTE *next;
}ROUTE;

//0X8607 del route
typedef struct _DEL_ROUTE
{
	UINT8   routeTal;
	UINT32	routeId1;
	UINT32  routeId2;
//	...
}DEL_ROUTE;

//0x8701 traver record down
typedef struct _TRAV_RECORD_DOWN
{
	UINT8	cmd;
	UINT32 	drvCode;
	UINT8	Idcard[20];
	UINT8	time[6];
	UINT32	coefficient;
}TRAV_RECORD_DOWN;

typedef struct _INSTALL_ARGS_STR
{
    UINT16 seqNum;//发送GPRS数据的序列号
    UINT8 terminalTel[6];//终端电话号码
    UINT8  tmType[20];//终端类型
    UINT8  tmlId[8];//终端ID
    UINT8 mfrId[5];//厂商id  BCD 码值
    UINT8  Akey[MAX_Akey_LEN]; //鉴权码
    UINT8 vin[17];//车辆vin号
    UINT8 plateType[12];//车牌分类
    //UINT8 vehicleChrtCft[3];//车辆特征系数
    UINT32 vehicleChrtCft;//车辆特征系数
    UINT8 hwVersion[20];
    UINT8 swVersion[20];

    SET_ARGS_STR set;
	
}INSTALL_ARGS_STR;

//0x8105 terminal ctl (cmd args table 15 )
typedef struct _CTRL_CMD_STR
{
    UINT8 cnt;
    UINT8 apn[30];
    UINT8 usr[30];
    UINT8 code[50];
    UINT8 ip[40];
    UINT16 tcpPort;
    UINT16 udpPort;
    UINT8 mfrId[5];//BCD 码值
    UINT8  Akey[MAX_Akey_LEN]; //鉴权码
    UINT8 hwVersion[20];
    UINT8 swVersion[20];
    UINT8 url[100];
    UINT16 cntTm;

}CTRL_CMD_STR;

/***********Terminal to platform.**********/

//0x0001 terminal common reply
typedef struct _TERM_COM_RPY
{
	UINT16 rpySerNum;
	UINT16  rpyId;
	UINT8   result;
}TERM_COM_RPY;

//0x0002 terminal heartbeat empty

//0x0003 terminal logout empty

//0x0100 terminal register

/*//0x0102 terminal auth
typedef struct _TERM_AUTH
{
	UINT8	Akey[MAX_Akey_LEN];
}TERM_AUTH;
*/
//0x0104 search terminal args rpy
typedef struct _SERCH_TERM_ARGS
{
	UINT16 seqNum;
	UINT8  argNum;
	TERM_ARGS  termArg;	
}SERCH_TERM_ARGS;

/*******pos struct start******/
//0x0200  position add
/*typedef struct _GPS_DATA
{
	UINT32	latitude;
	UINT32 	longitude;
	UINT16	altitude;
	UINT16	speed;
	UINT16	direct;
	UINT8	time[6];
}GPS_DATA;
*/
typedef struct _GPS_DATA
{
    INT32 latitude;
    INT32 north;
    INT32 longitude;
    INT32 east;
    INT16 speed;
    INT32 speedtype;  // 1为速度传感器的速度；0为GPS速度
    INT16 course;       //航向
    INT16 height;
    UINT8 tm[6];
    INT32 distance;   //里程
}GPS_DATA;

typedef struct _POS_BASIC
{
	UINT32 alarmFlag;
	UINT32  status;
	GPS_DATA  gps;
}POS_BASIC;

typedef struct _OVER_SPEED_ADD		//over speed alarm
{
    UINT8 type;
    UINT32 id;
}OVER_SPEED_ADD;

typedef  struct  _AREA_ALARM		//in or out area alarm
{
    UINT8 type;
    UINT32 id;
    UINT8 drc;
}AREA_ALARM;

typedef struct _DRV_TM	//drv time not enough or longer
{
    UINT32 id;
    UINT16  tm;
    UINT8 result;
}DRV_TM;

typedef struct _POS_ADD
{
    UINT32 mileage;
    UINT16 fuel;
    UINT16  speed;
    OVER_SPEED_ADD  overSpdAdd;
    AREA_ALARM areaAdd;
    DRV_TM drvTm;
}POS_ADD;

typedef struct _POS_INFO
{
    UINT8  addFlag;// bit0 <->id 0x01,bit1 <->id=0x02,bit2<->id=0x03,bit4<->id=0x11,bit5<->id=0x12,bit6<->id=0x13
    POS_BASIC	base;
    POS_ADD 	add;

}POS_INFO;
/*********end********/

//0x0201 position info search reply
typedef struct _POSINFO_SERCHRPY
{
	UINT16	rpySerNum;
	POS_INFO	posInfo;
}POSINFO_SERCHRPY;


//0x0303 msg play or cancel
typedef struct _MSG_PLAY_CANCEL
{
	UINT8	msgType;
	UINT8	plyCancelFlag;
}MSG_PLAY_CANCEL;

//0x0500 vehicle control reply
typedef struct _VEHICLE_CTRL_RPY
{
	UINT16	rpySerNum;
	POS_INFO  posInfo;
}VEHICLE_CTRL_RPY;

typedef struct _RECORD_01H
{
	UINT32 drvNum;
	UINT8 carNum[18];
}RECORD_01H;
typedef struct _RECORD_02H
{
	UINT8 clock[6];
}RECORD_02H;
typedef struct _RECORD_03H
{
	UINT32 mile1;
	UINT8 time1[5];
}RECORD_03H;
/*typedef struct _RECORD_04H
{
	UINT8 vehicleChrtCft[3];
}RECORD_04H;
*/
typedef struct _RECORD_05H
{
	UINT8 time1[5];
	UINT8 speed1;
}RECORD_05H;
/*typedef struct _RECORD_06H
{
	UINT8 vin[17];
	UINT8 PlateNum[MAX_PLATE_NUM_LEN];
	UINT8 plateType[12];
}RECORD_06H;
*/
typedef struct _RECORD_07H
{
	UINT8 time[6];
	UINT8 speed;
}RECORD_07H;
typedef struct _RECORD_08H
{
	UINT32 mile2;
	UINT8 time2[5];
}RECORD_08H;
typedef struct _RECORD_09H
{
	UINT8 time2[5];
	UINT8 speed2;
}RECORD_09H;
typedef struct _RECORD_11H
{
	UINT8 carNum[18];
	UINT8 start[5];
	UINT8 end[5];
}RECORD_11H;
//0x0700 travel record upload
typedef struct _TRAV_RECD_UP
{
     UINT16  seqNum;
     UINT8   cmdWord;
     RECORD_01H rd01;   
     RECORD_02H rd02;   
     RECORD_03H rd03;   
     RECORD_05H *rd05;   
     RECORD_07H rd07[10];   
     RECORD_08H rd08;   
     RECORD_09H *rd09;   
     RECORD_11H *rd11;   
}TRAV_RECD_UP;

//0x0701 elec bill upload
typedef struct _ELEC_BILL_UP
{
     UINT32 elcBillLen;
     UINT8  elcBillCtent[MAX_TRANS_CONTENT];
}ELEC_BILL_UP;

//0x0702 driver info upload
typedef struct _DRIVER_INFO
{
    UINT8 name[30];
    UINT8 IDcard[20];//身份证
    UINT8 drvNum[40];//驾驶证号
    UINT8 orgName[MAX_ORG_NAME_LEN];
}DRIVER_INFO;

//0x0800 media event upload
typedef struct _MEDIA_EVENT_UP
{
	UINT32	mediaDatID;
	UINT8	mediaType;
	UINT8	mediaCode;
	UINT8	eventCode;
	UINT8	channelID;
	
}MEDIA_EVENT_UP;

//0x0801 media data upload
typedef struct _MEDIA_DAT_UP
{
	UINT32	mediaDatID;
	UINT8	mediaType;
	UINT8	mediaCode;
	UINT8	eventCode;
	UINT8	channelID;
	UINT8	mediaPkg[MAX_SIZE];
}MEDIA_DAT_UP;

typedef struct _MEDIA_SERCH_DAT //media search table 71
{
	UINT8	mediaType;
	UINT8	channelID;
	UINT8	eventCode;
	POS_INFO	posInfo;
}MEDIA_SERCH_DAT;

//0x0802  save media data search reply
typedef struct _SAVMEDAT_SECH_RPY
{
	UINT16	rpySerNum;
	UINT16	medDatTotal;
	MEDIA_SERCH_DAT medSerchDat;
}SAVMEDAT_SECH_RPY;

//0x0900 data up trans
typedef struct _DAT_UP_TRANS
{
	UINT8	traMsgTy;
	UINT8	traMsgCont[MAX_SIZE];
}DAT_UP_TRANS;
//0x0901
typedef struct _DAT_COMPRESS
{
	UINT32	cmpMsgLen;
	UINT8	cmpMsgBody[MAX_SIZE];//compress msg body
}DAT_COMPRESS;
//0x0A00
typedef struct _TERM_RSA_KEY
{
	UINT32	e;
	UINT8	n[128];
}TERM_RSA_KEY;


/**************************************************************************
 *                           全局变量声明                                      *
 **************************************************************************/
extern INSTALL_ARGS_STR g_installArgs;


/**************************************************************************
 *                     全局函原型                                      *
 **************************************************************************/
INT32 proc_lc_jt808( UINT8*pdata, INT32 datalen);

#endif //__JT808_H
